package com.zzt.video.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzt.video.model.dto.SeriesSearchParam;
import com.zzt.video.model.dto.SeriesShowDto;
import com.zzt.video.model.entity.Series;
import com.zzt.video.service.SeriesService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.stream.Collectors;

@RestController
@RequestMapping("/series")
public class SeriesController {

    @Autowired
    private SeriesService seriesService;

    @PostMapping("/search")
    public ResponseEntity<Page<Series>> search(@RequestBody SeriesSearchParam param) {
        return ResponseEntity.ok(seriesService.getSeriesByKeywordWithPagination(param));
    }

    @GetMapping("/watch/{seriesId}")
    public void watchSeries(HttpServletRequest request, @PathVariable("seriesId") Long seriesId){
        seriesService.watchSeries(request, seriesId);
    }

    @GetMapping("/getById/{seriesId}")
    public ResponseEntity<SeriesShowDto> getById(HttpServletRequest request, @PathVariable("seriesId") Long seriesId){
        seriesService.watchSeries(request, seriesId);
        return ResponseEntity.ok(seriesService.getSeries(seriesId));
    }
}

